import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet("/redireForwardServlet")
public class redireForwardServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("user");
        System.out.println(name);
        String password = request.getParameter("pwd");
        if(name==null || name.length()==0){
            //重定向
            response.sendRedirect("redirectForward.jsp");
        } else if (password==null ||password.length()==0) {
            response.sendRedirect("redirectForward.jsp");
        } else if (name.length()>0&&password.length()>0) {
            //转发
            RequestDispatcher dis= request.getRequestDispatcher("ShowServlet");
            dis.forward(request,response);
        }
    }
}
